/* 
 * Copyright 2009 Shared Object (www.sharedobject.ch)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edos.prm.project;

import edos.prm.actor.Actor;
import edos.prm.engine.PRM;

/**
 * A {@code Topic} is employed by a project to classify its artifacts.
 * <p>
 * A {@code Topic} is also the basis for forming an ontology describing the
 * project.
 * 
 * @version 1.0
 */
public final class Topic {
	
	private String name;
	private Project project;
	private Actor definer;

	/**
	 * Creates a {@code Topic} with a given name, and belonging to the
	 * specified project.
	 * 
	 * @param name the String name given to this topic.
	 * @param project the project for which the topic is defined.
	 */
	Topic(String name, Project project) {
		this.name = name.toLowerCase();
		this.project = project;
		this.definer = PRM.getTaskManager().currentTask().getActor();
		}

	/**
	 * Returns the name of this topic.
	 * 
	 * @return the String name of this topic.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Indicates the project in which this topic is defined.
	 * 
	 * @return the project for which this topic is defined.
	 */
	public Project getProject() {
		return project;
	}
	
	/**
	 * Return the actor that defined this topic.
	 * 
	 * @return the actor who defined the topic.
	 */
	public Actor getDefiner() {
		return this.definer;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((project == null) ? 0 : project.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Topic other = (Topic) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (project == null) {
			if (other.project != null)
				return false;
		} else if (!project.equals(other.project))
			return false;
		return true;
	}

}
